import 'package:flutter/material.dart';
import 'package:osc/common/constants.dart';
import 'package:osc/utils/string_util.dart';
import 'package:fluttertoast/fluttertoast.dart';

class PdUtil{
  static String getFullUrl(String str) {
    if(str == null || str.isEmpty){
      return "";
    } else {
      if(!str.startsWith("http")) {
        if (str.startsWith("/")) {
          str = Constant.OSC_OPEN_API_HOST_URL_WITHOUT_SPLASH + str;
        } else {
          str = Constant.OSC_OPEN_API_HOST_URL + str;
        }
      }
      return str;
    }
  }

  static String getImagePath(String imageName, {bool png = true, bool jpg = false, String fullName}){
    if(png) {
      return "images/$imageName.png";
    } else if(jpg){
      return "images/$imageName.jpg";
    }
    return "images/$fullName";
  }

  static String getEmojiPath(String imageName){
    return "emoji/$imageName.png";
  }

  static double getMoney(String moneyStr){
    if(StringUtil.isEmpty(moneyStr)){
      return 0;
    }
    return double.parse(moneyStr.replaceAll(",", ""));
  }

  static String getDateWithDay(String time){
    DateTime dateTime = DateTime.parse(time);
    return "${dateTime.year}-${dateTime.month}-${dateTime.day}";
  }

  static void showToast({@required String msg, ToastGravity gravity = ToastGravity.CENTER}){
    Fluttertoast.showToast(msg: msg, gravity: gravity);
  }
}